package com.briup.server.web.controller;

import com.briup.common.response.Result;
import com.briup.server.domain.bean.User;
import com.briup.server.security.Permission;
import com.briup.server.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

// 导入系统常量类中的角色名常量，static静态导入，方便直接使用角色名常量
import static com.briup.common.constant.SystemConstant.ADMIN_ROLE_NAME;
import static com.briup.common.constant.SystemConstant.LAB_ADMIN_ROLE_NAME;


@Tag(name = "测试模块")
@RestController
@RequestMapping("/test/users")
@RequiredArgsConstructor
public class TestController {

    private final UserService userService;

    @Permission({ADMIN_ROLE_NAME, LAB_ADMIN_ROLE_NAME})
    @Operation(summary = "查询用户列表")
    @GetMapping("/list")
    public Result<List<User>> list() {
        List<User> list = userService.list();
        return Result.success(list)
                .apply("查询用户列表成功");
    }

    @Permission(ADMIN_ROLE_NAME)
    @Operation(summary = "列举所有实验室管理员用户")
    @GetMapping("/admin/list")
    public Result<List<User>> adminList() {
        List<User> list = userService.labsAdminList();
        return Result.success(list)
                .apply("查询管理员用户列表成功");
    }
}
